load("//tools:integration.bzl", "LOCAL_NPM_PACKAGES", "integration_test")

# Name of the generated app.
APP_NAME = "ng-add-standalone"

integration_test(
    name = "test",
    srcs = glob(["**/*"]),
    commands = [
        "pnpm i",

        # Generate a new standalone project with the default options.
        # Skip installation since we installed the dependencies already.
        "pnpm ng new --defaults --standalone --skip-install --style=scss --skip-git --name=%s" % APP_NAME,
        # Delete the package.json that the CLI generated since we want to use the existing one.
        "rm -f %s/package.json" % APP_NAME,
        # Delete the Karma config since we need to use a headless browser.
        "rm -f %s/karma.conf.js" % APP_NAME,
        # Delete the tsconfig since we have a pre-defined one.
        "rm -f %s/tsconfig.json" % APP_NAME,
        # We can't name the checked-in config `angular.json`, because the CLI doesn't allow
        # `ng new` to run in a directory that has an `angular.json` already.
        "mv _angular.json angular.json",
        # Delete the angular.json since we have a specific config for the test.
        "rm -f %s/angular.json" % APP_NAME,
        # Move the generated project one level up so it can reuse the package.json and node_modules.
        "mv %s/* ." % APP_NAME,
        # Install Material and run the unit tests.
        "pnpm ng add @angular/material",
        "pnpm test",
    ],
    npm_packages = LOCAL_NPM_PACKAGES,
    setup_chromium = True,
    tags = [
        # This test relies on `yarn` so there needs to be internet access.
        "requires-network",
    ],
)
